<template>
  <div class="sidebar">
    <el-menu
      class="sidebar-el-menu"
      @open="handleOpen"
      :collapse="collapse"
      background-color="#324157"
      text-color="#bfcbd9"
      active-text-color="#20a0ff"
      unique-opened
      router
      @select="handleSelect"
    >
      <template v-for="item in items" :index="item.index">
        <template v-if="item.subs">
          <el-submenu :index="item.index" :key="item.index">
            <template slot="title">
              <i :class="item.icon"></i>
              <span slot="title">{{ item.title }}</span>
            </template>
            <template v-for="subItem in item.subs">
              <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
                <template slot="title">{{ subItem.title }}</template>
                <el-menu-item
                  v-for="(threeItem,i) in subItem.subs"
                  :key="i"
                  :index="threeItem.index"
                >{{ threeItem.title }}</el-menu-item>
              </el-submenu>
              <el-menu-item v-else :index="subItem.index" :key="subItem.index">{{ subItem.title }}</el-menu-item>
            </template>
          </el-submenu>
        </template>
        <template v-else>
          <el-menu-item :index="item.index" :key="item.index">
            <i :class="item.icon"></i>
            <span slot="title">{{ item.title }}</span>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script>
import bus from "../common/bus";
import store from "../../store/index.js";
export default {
  data() {
    return {
      collapse: false,
      items: [
        {
          icon: "el-icon-lx-share",
          index: "dashboard",
          title: "我的工作台"
        },
        {
          icon: "el-icon-lx-calendar",
          index: "table",
          title: "教务管理",
          subs: [
            {
              index: "RowcourseAdmin",
              title: " 排课管理"
            },
            {
              index: "ClassAdmin",
              title: " 班级管理"
            }
          ]
        },
        {
          icon: "el-icon-lx-peoplefill",
          index: "table1",
          title: "学员管理",
          subs: [
            {
              index: "Formalcadets",
              title: " 正式学员"
            },
            {
              index: "IntentionalTrainee",
              title: " 意向学员"
            }
          ]
        },
        {
          icon: "el-icon-goods",
          index: "table2",
          title: "财务管理",
          subs: [
            {
              index: "OrderAdmin",
              title: " 订单管理"
            },
            {
              index: "Bankaccount",
              title: " 银行账户"
            },
            {
              index: "Settlement",
              title: " 结算中心"
            }
          ]
        },
        {
          icon: "el-icon-lx-goods",
          index: "table3",
          title: "商品管理",
          subs: [
            {
              index: "Discounts",
              title: " 折扣设置"
            }
          ]
        },
        {
          icon: "el-icon-setting",
          index: "table4",
          title: "机构管理",
          subs: [
            {
              index: "Basicinformation",
              title: " 基础信息"
            },
            {
              index: "Classroom",
              title: " 教室管理"
            },
            {
              index: "Personnel",
              title: " 权限管理"
            }
          ]
        }
      ]
    };
  },
  created(){
    this.ply();
  },
  computed: {
    // onRoutes(){
    //     return this.$route.path.replace('/','');
    // }
  },
  methods: {
    handleOpen(key, keypath) {
      // console.log(key, keypath);
      // console.log(this.$route.path);
    },
    // aaa() {
    //   this.$store.commit("changData", 1123123);
    // },
    handleSelect(key, keyPath) {
      // console.log(key);
      if(this.$route.path == "/home/RowCourse"){
        this.$confirm('确定离开当前页面?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
            }).then(() => {
                this.$router.push('/Dashboard');
            }).catch(() => { 
              this.$router.push("/RowcourseAdmin")
        });
      }
      this.$router.push("/" + keyPath);
    }
  },
  mounted() {
    // console.log(this.$store)
  },
  created() {
    // 通过 Event Bus 进行组件间通信，来折叠侧边栏
    bus.$on("collapse", msg => {
      this.collapse = msg;
    });
  }
};
</script>

<style scoped>
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 70px;
  bottom: 0;
  overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
  width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
  width: 250px;
}
.sidebar > ul {
  height: 100%;
}
</style>
